import tornado.web
import tornado.ioloop
from . import utils
import json
'''
#
#7.1 物体检测
同步
    http://ip:port/pic/detect
    {
        "fileUrl":"",
        "id":"1"
    }

aeroplane
bicycle
bird
boat
bottle
bus
car
cat
chair
cow
diningtable
dog
horse
motorbike
person
pottedplant
sheep
sofa
train
tvmonitor
IDcard
officialSeal
logo
bankCard
gun
cutter
maskedFace
commonFace
beardFace
sedan
coach
'''
class PicDetect(tornado.web.RequestHandler):

    def post(self, *args, **kwargs):
        resp = None
        try:
            data=json.loads(self.request.body)
            print(data)
            paramerror = utils.checkParam(data,{
                "fileUrl":"",
                "id":"1"
            })
            if paramerror == '': #ok
                resp = {
                    "state":{
                        "ok":1,
                        "failed": ""
                    },
                    "result":[{
                        "x":161,
                        "y":0,
                        "w":160,
                        "h":256,
                        "name":"person",
                        "score":"0.84545"
                    }],
                    "id":data['id']
                }
            else: #failed
                resp = {
                    "state":{
                        "ok":0,
                        "failed": paramerror
                    },
                    "result":[]
                }

        except BaseException as e:
            resp = {
                "state":{
                    "ok":0,
                    "failed": str(e)
                },
                "result":[]
            }

        self.write(resp)
